package freedom.ms.registry.contoller;

import java.text.MessageFormat;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author charlie
 *
 */
@Controller
public class HomeController {

	@Value("${spring.application.name}")
	String name;
	@Value("${server.port}")
	String port;

	@RequestMapping({"/inf"})
	@ResponseBody
	public String info() {
		return MessageFormat.format("{0} {1}", name, port);
	}

	@RequestMapping({ "/index", "/" })
	public String index() {
		return "index";
	}

	public static final String LOGIN_MSG = ">>>>>>>>>>>login...error:{0}, logout:{1}";

	@GetMapping("/login")
	public String login(HttpServletRequest request, String error, String logout) {
		System.out.println(MessageFormat.format(LOGIN_MSG, error, logout));
		return "login";
	}

	@GetMapping("/admin")
	public String admin() {
		return "admin";
	}

	@GetMapping("/user")
	public String user() {
		return "user";
	}

	@GetMapping("/about")
	public String about() {
		return "about";
	}

	@GetMapping("/403")
	public String error403() {
		return "error/403";
	}
}
